{% extends "process/base.html" %}
{% load nm %}
{% load js %}

{% block head_resources %}
{{block.super}}
{% jsinclude "nm" %}
<style type="text/css">
.errorlist { color: red; }
#newmaint-lookup {
  display: none;
  margin: 0.5em;
}
</style>
<script type="text/javascript">
(function($) {
  var csrf_token;

  function main()
  {
    csrf_token = $("input[name='csrfmiddlewaretoken']").val();
    $("#newmaint-lookup").show();
    $("#newmaint-lookup-errors").hide();
    $("#newmaint-lookup-form").submit(function(evt) {
      evt.preventDefault();
      var url = $("#newmaint-url").val();
      console.log(url);
      $.ajax({
        url: "{% url 'process_email_lookup' pk=process.pk %}",
        method: "POST",
        data: {
          url: url,
          csrfmiddlewaretoken: csrf_token,
        },
        success: function(data, textStatsu, jqXHR) {
          if (data.error)
          {
            $("#newmaint-lookup-errors").text(data.error).show();
          } else {
            $("#newmaint-lookup-errors").hide();
            $("#id_statement").val(data.msg);
          }
        },
        error: function(jqXHR, textStatus, errorThrown) {
          $("#newmaint-lookup-errors").text(jqXHR.responseText).show();
        },
      });
      return false;
    });
  }
  $(main);
})(jQuery);
</script>
{% endblock %}

{% block content %}

<h1>Add {{type_desc}}</h1>

{% include explain_template with edit=True %}

{% if blurb %}
<p>For your convenince, you can generate the signed statement with this
command, and the site will recognise the text and accept it without a need of
manual validation of its content:</p>

<pre>
(
  {% for line in blurb %}echo {{line}}
  {% endfor %}
) | gpg --clearsign --default-key {{visitor.fpr}}
</pre>
{% endif %}

<p>Use <tt>gpg --clearsign --default-key {{fpr}}</tt> to generate the
signed statement. Tip: pipe it to <tt>xclip</tt> to have it copied to the
clipboard for easy pasting.</p>

<p>It is a good idea to include some context information like the date and
nm.debian.org in the text, in case someone tries to reuse the signed statement
somewhere else.</p>

<p>The signature will be verified using the key {{fpr|fingerprint}}</p>

{% if requirement.type != "sc_dmup" %}
<p>The statement will be sent to <a href="https://lists.debian.org/debian-newmaint">debian-newmaint</a>
as <tt>{{visitor.fullname}}
  {% if "edit_email" in visit_perms %}
  <a href="{% url 'person_edit_email' key=visitor.lookup_key %}">&lt;{{visitor.email}}&gt;</a></tt>.
  {% else %}
  &lt;{{visitor.email}}&gt;</tt>.
  {% endif %}
</p>
{% endif %}

<form action="" method="post">{% csrf_token %}
  {% for hidden in form.hidden_fields %}{{ hidden }}{% endfor %}
  {% for field in form.visible_fields %}
  {{ field.label_tag }}<br>
  {{ field }}<br>
  {{ field.errors }}
  {% endfor %}        
  {{ form.non_field_errors }}
  <input type="submit" value="Submit">
</form>

<div id="newmaint-lookup">
<form id="newmaint-lookup-form">
  Lookup from <a href="https://lists.debian.org/debian-newmaint/">debian-newmaint</a>:
  <input id="newmaint-url" type="text" placeholder="https://lists.debian.org/debian-newmaint/…" size="80"></input>
  <div id="newmaint-lookup-errors">
  </div>
</form>
</div>

{% endblock %}
